<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <title>医院管理系统</title>
  <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <link rel="stylesheet" href="../../static/css/style.css" th:href="@{/css/style.css}"/>
</head>
<body>
<div th:replace="~{common/layout :: header}"></div>
<div th:replace="~{common/layout :: sidebar}"></div>
<div class="container mt-5">
  <h1 class="mb-4">医院列表</h1>
  <a href="/hospitals/add" class="btn btn-primary mb-3">添加新医院</a>
  <hr>
  <table class="table table-bordered">
    <thead class="thead-dark">
    <tr>
      <th>ID</th>
      <th>名称</th>
      <th>图片</th>
      <th>电话</th>
      <th>地址</th>
      <th>营业时间</th>
      <th>状态</th>
      <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <tr th:each="hospital : ${hospitals}">
      <td th:text="${hospital.hpId}"></td>
      <td th:text="${hospital.name}"></td>
      <td><img th:src="@{${hospital.picture}}" alt="图片" width="50"></td>
      <td th:text="${hospital.telephone}"></td>
      <td th:text="${hospital.address}"></td>
      <td th:text="${hospital.businessHours}"></td>
      <td th:text="${hospital.state == 1 ? 'Active' : 'Inactive'}"></td>
      <td>
        <a th:href="@{/hospitals/view/{id}(id=${hospital.hpId})}" class="btn btn-info btn-sm">详情</a>
        <a th:href="@{/hospitals/edit/{id}(id=${hospital.hpId})}" class="btn btn-warning btn-sm">编辑</a>
        <button class="btn btn-danger btn-sm" th:data-id="${hospital.hpId}" onclick="deleteHospital(this)">删除</button>
      </td>
    </tr>
    </tbody>
  </table>
</div>
<script>
  function deleteHospital(element) {
    var hospitalId = element.getAttribute("data-id");
    if (confirm('确定要删除该医院吗？')) {
      window.location.href = '/hospitals/delete/' + hospitalId;
    }
  }
</script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.4/dist/umd/popper.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>
